package com.fly.snailrun.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author：gaoxu
 * @date：Created in 2024/7/25 15:08
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
    @Bean
    public Docket createRestApi() {
        ParameterBuilder parameterBuilder = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        parameterBuilder.name("X-PAAS-REQUEST-ID").description("request-id")
                .modelRef(new ModelRef("string")).parameterType("header")
                //header中的X-PAAS-REQUEST-ID参数必填
                .required(true).build();
        pars.add(parameterBuilder.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.fly.snailrun.access"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(pars)
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("snail-run 剪映工具化工程使用")
                .description("snail-run-doc接口文档")
                .termsOfServiceUrl("Api for cloud-service")
                .version("1.0.0")
                .license("Apache 2.0")
                .licenseUrl("https://stackoverflow.com/")
                .termsOfServiceUrl("http://localhost:7810/snail-run/")
                .contact(new Contact("snail-run group", "www.bailian.com", "json.word.7@outlook.com"))
                .build();
    }
}
